# Responsability
# Send to the slaves all the files, functions and data they need and execute the needed code

SlavesFeeder <- setRefClass(    
  "slavesfeeder"
  , fields = list(
      measurements="data.frame",
      priorProbabilityDistribution="data.frame"
      )
  , methods = list(
    #
    #
    # Constructor
    #
    #
    initialize = function(..., measurements=data.frame(),
                          priorProbabilityDistribution=data.frame())
    { 
      callSuper(..., measurements = measurements,
                priorProbabilityDistribution=priorProbabilityDistribution)
    },
    #
    #
    # Send objects to the slaves
    #
    #
    feedSlaves = function() {
      
      logdebug("METHOD IN: feedSlaves")
      
      mpi.bcast.Robj2slave(configuration)
      mpi.bcast.Robj2slave(measurements)
      mpi.bcast.Robj2slave(priorProbabilityDistribution)
      
      logdebug("METHOD OUT: feedSlaves")
      
      
    },
    #
    #
    # Execute code in the slaves
    # Call the function in all the slaves to get them ready to
    # undertake tasks
    #
    #
    whipSlaves = function() {
      
      logdebug("METHOD IN: executeSlaves")
      
      mpi.bcast.cmd(source("Logging.R"))
      mpi.bcast.cmd(source("Slave.R"))
      mpi.bcast.cmd(source('Ldndc.R'))
      mpi.bcast.cmd(source('Likelihood.R'))
      mpi.bcast.cmd(source('ChainState.R'))
      mpi.bcast.cmd(library(stats))
      mpi.bcast.cmd(Logging())
      mpi.bcast.cmd(foldslave())
      
      logdebug("METHOD OUT: executeSlaves")
    }
    
  )#End methods List 
  
)#End RefClass